package Base.线程的优先级;

/**
 * @author 陈鹏
 */
public class Example07 {
    public static void main(String[] args) {
        Thread thread1=new Thread(()->{
            for (int i=0;i<10;i++){
                System.out.println(Thread.currentThread().getName()+"正在输出i："+i);
        }
        });
        Thread thread2=new Thread(()->{
            for (int j=0;j<10;j++){
                System.out.println(Thread.currentThread().getName()+"正在输出j："+j);
        }
        },"优先级更高的线程");
//        设置优先级（也是指概率）,通过setPriority()方法设置可以写入数字或者提供的常量
        thread1.setPriority(5);
//        thread2获得运行的机会更大
        thread2.setPriority(10);
        thread1.start();
        thread2.start();
    }
}
